﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;

namespace BtoBSWT315.User
{
    public partial class Modify_Company : System.Web.UI.Page
    {
        public string qylbvalue;

        private void Page_Load(object sender, System.EventArgs e)
        {
            // 在此处放置用户代码以初始化页面
            if (Session["user"] == null)
            {
                Response.Redirect("../Login.aspx");
            }
            if (!IsPostBack)
            {
                EditDataBind();
            }
        }


        private void EditDataBind()
        {
            //引入数据库操作类
            Admin.Admin_ClassDb classdb = new Admin.Admin_ClassDb();

            //定义所需SQL语句
            string sql = "select * from qyml where [user]='" + Session["user"] + "'";

            //SqlDataReader dr=Sqlcomm.ExecuteReader();
            OleDbDataReader dr = classdb.Getdr(sql);

            if (dr.Read())
            {
                qymc.Text = dr["qymc"].ToString();             //企业名称
                address.Text = dr["address"].ToString();       //街道地址
                name.Text = dr["name"].ToString();             //联系人
                phone.Text = dr["phone"].ToString();           //电话
                mobile.Text = dr["mobile"].ToString();         //手机
                fax.Text = dr["fax"].ToString();               //传真
                email.Text = dr["email"].ToString();           //电子邮件
                web.Text = dr["web"].ToString();
                qyxz.SelectedValue = dr["qyxz"].ToString();             //企业性质

                QQ.Text = dr["qq"].ToString();

                //经营模式
                if (dr["qylb"].ToString().IndexOf("生产型") >= 0)
                {
                    CheckBox1.Checked = true;
                }
                if (dr["qylb"].ToString().IndexOf("贸易型") >= 0)
                {
                    CheckBox2.Checked = true;
                }
                if (dr["qylb"].ToString().IndexOf("服务型") >= 0)
                {
                    CheckBox3.Checked = true;
                }
                if (dr["qylb"].ToString().IndexOf("政府或其它机构") >= 0)
                {
                    CheckBox4.Checked = true;
                }
                txtqyjj.Text = dr["qyjj"].ToString();             //企业简介
            }
            dr.Close();
        }


        private void Button1_Click(object sender, System.EventArgs e)
        {
            if (CheckBox1.Checked == true)
            {
                qylbvalue = CheckBox1.Text.ToString();
            }
            if (CheckBox2.Checked == true)
            {
                qylbvalue += "," + CheckBox2.Text.ToString();
            }
            if (CheckBox3.Checked == true)
            {
                qylbvalue += "," + CheckBox3.Text.ToString();
            }
            if (CheckBox4.Checked == true)
            {
                qylbvalue += "," + CheckBox4.Text.ToString();
            }

            if ("" == qymc.Text && "" == address.Text)
            {
                Response.Write("<script>alert('请按要求填写!');</script>");
                Response.Write("<script>history.go(-1);</script>");
                Response.End();
            }

            string sql = "update qyml set qymc='" + qymc.Text + "',QQ='" + QQ.Text+ "',address='" + address.Text + "',name='" + name.Text + "'";
            sql += " ,phone='" + phone.Text + "',fax='" + fax.Text + "',email='" + email.Text + "',web='" + web.Text + "'";
            sql += ",qyxz='" + qyxz.SelectedValue + "',qyjj='" + txtqyjj.Text + "'";
            sql += ",qylb='" + qylbvalue + "' where [user]='" + Session["user"] + "'";
            //引入数据库操作类
            Admin.Admin_ClassDb classdb = new Admin.Admin_ClassDb();
            if (classdb.GetNonResult(sql) != 0)
            {
                Response.Write("<script>alert('操作成功');</script>");
                Response.Write("<script>history.go(-2);</script>");
                Response.End();
            }
            else
            {
                Response.Write("<script>alert('操作失败！请重新填写。');</script>");
                Response.Write("<script>history.go(-1);</script>");
                Response.End();
            }

        }

        #region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }

        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.Button1.Click += new System.EventHandler(this.Button1_Click);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion
    }
}